package com.jiyun.play.controller;

import com.domain.Orders;
import com.jiyun.play.service.OrdersService;
import com.spyx.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orders")
@CrossOrigin
public class OrdersController {
    @Autowired
    private OrdersService ordersService;
    @PostMapping("/add")
    public Result add(@RequestBody @Validated Orders orders){
        Orders order = ordersService.addOrders(orders);
        return Result.ok(order);
    }
    @PostMapping("/list")
    public Result list(){
        List<Orders> list = ordersService.findAll();
        return Result.ok(list);
    }
    @PostMapping("/findById")
    public Result findById(@RequestParam("id") Integer id) {
        Orders byId = ordersService.getById(id);
        return Result.ok(byId);
    }


}
